home *** CD-ROM | disk | FTP | other *** search
/ Die Ultimative Software-P…i Collection 1996 & 1997 / Die Ultimative Software-Pakete CD-ROM fur Atari Collection 1996 & 1997.iso / g / gnu_c / pmlsrc23.zoo / envtests / testldexp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-19  |  2.0 KB  |  65 lines

  1. /************************************************************************
  2.  *                                    *
  3.  *                N O T I C E                *
  4.  *                                    *
  5.  *            Copyright Abandoned, 1987, Fred Fish        *
  6.  *                                    *
  7.  *    This previously copyrighted work has been placed into the    *
  8.  *    public domain by the author (Fred Fish) and may be freely used    *
  9.  *    for any purpose, private or commercial.  I would appreciate    *
  10.  *    it, as a courtesy, if this notice is left in all copies and    *
  11.  *    derivative works.  Thank you, and enjoy...            *
  12.  *                                    *
  13.  *    The author makes no warranty of any kind with respect to this    *
  14.  *    product and explicitly disclaims any implied warranties of    *
  15.  *    merchantability or fitness for any particular purpose.        *
  16.  *                                    *
  17.  ************************************************************************
  18.  */
  19.  
  20.  
  21. /*
  22.  *  FILE
  23.  *
  24.  *    testldexp.c    test the runtime environment function ldexp
  25.  *
  26.  *  DESCRIPTION
  27.  *
  28.  *    This simple minded program is provided to aid in testing
  29.  *    the "ldexp" function assumed to be provided in the runtime
  30.  *    environment.  If not provided, a suitable substitute can
  31.  *    be coded in C, however the necessary code is very machine
  32.  *    dependent and is generally almost trivial to code in assembly
  33.  *    language for the specific host machine.
  34.  *
  35.  *    The ldexp() function takes two arguments, the first is a double
  36.  *    which is the mantissa of the returned double value.  The second
  37.  *    is an int which is the exponent of the returned double.  The
  38.  *    result is (mantissa * (2 ** exp)).
  39.  *
  40.  *    See "frexp(3C)" in the Unix System V User's Manual for more
  41.  *    information.
  42.  *
  43.  *    This program is typically used as:
  44.  *
  45.  *        testldexp <testldexp.in >junkfile
  46.  *        diff testldexp.out junkfile
  47.  *
  48.  */
  49.  
  50. #include <stdio.h>
  51.  
  52. extern double ldexp ();
  53.  
  54. main ()
  55. {
  56.     double dmant;            /* Mantissa, 0.5 LE |dmant| LT 1.0 */
  57.     int intexp;                /* Exponent as power of 2 */
  58.     double result;            /* dmant times 2 to the intexp */
  59.     
  60.     while (scanf ("%le %d", &dmant, &intexp) == 2) {
  61.     result = ldexp (dmant, intexp);
  62.     printf ("%le\n", result);
  63.     }
  64. }
  65.